package com.astronomia.wheels.date_utils;


import java.text.DateFormat;
import java.text.ParseException;
import java.text.ParsePosition;
import java.text.SimpleDateFormat;
import java.time.DayOfWeek;
import java.time.Instant;
import java.time.LocalDate;
import java.time.LocalDateTime;
import java.time.LocalTime;
import java.time.ZoneId;
import java.time.ZoneOffset;
import java.time.ZonedDateTime;
import java.time.temporal.TemporalAdjusters;
import java.util.ArrayList;
import java.util.Calendar;
import java.util.Date;
import java.util.GregorianCalendar;
import java.util.List;
import java.util.Locale;

public class DateTools {

    /**
     * @author zhijun.zhao
     * @date 2018/9/11 17:07
     * @param data1,data2
     * @return int
     * @Description:  日期时间之间对比
     */
    public static int compareDate(String data1, String data2) {


        DateFormat df = new SimpleDateFormat("yyyy-MM-dd hh:mm");
        try {
            Date dt1 = df.parse(data1);
            Date dt2 = df.parse(data2);
            if (dt1.getTime() > dt2.getTime()) {
                return 1;
            } else if (dt1.getTime() < dt2.getTime()) {
                return -1;
            } else {
                return 0;
            }
        } catch (Exception exception) {
            exception.printStackTrace();
        }
        return 0;
    }

    /**
     * @param birthday
     * @return  Integer
     * @author liyucheng
     * @date 2018/12/27 11:13
     * @description  生日提醒 1提醒 2 不提醒
     */
    public static Integer birthdayTips(Date birthday) {
        LocalDateTime dateTime = getDateToLocalDateTime(birthday);
        LocalDateTime now = LocalDateTime.now();
        dateTime.getDayOfMonth();
        if(dateTime.getMonthValue() == now.getMonthValue() && now.getDayOfMonth() == dateTime.getDayOfMonth()){
            return YnEnum.YES.getCode();
        }
        return YnEnum.NO.getCode();
    }


    /**
     * @author zhijun.zhao
     * @date 2018/9/11 17:12
     * @param
     * @return
     * @Description:  获取当前时间字符串  yyyy-MM-dd HH:mm
     */
    public static String getCurrentDateToString() {
            Date currentTime = new Date();
            SimpleDateFormat formatter = new SimpleDateFormat(DateStyle.YYYY_MM_DD_HH_MM.getValue());
            String dateString = formatter.format(currentTime);
            return dateString;
         }


    /**
     * @author zhijun.zhao
     * @date 2018/9/11 17:12
     * @param date
     * @return String
     * @Description:   时间格式转译，由data转为字符串
     */
    public static String getDateToString(Date date) {

        SimpleDateFormat formatter = new SimpleDateFormat(DateStyle.YYYY_MM_DD_HH_MM.getValue());
        String dateString = formatter.format(date);
        return dateString;
    }

    /**
     * @author zhijun.zhao
     * @date 2018/9/11 17:12
     * @param date
     * @return String
     * @Description:   时间格式转译，由data转为字符串
     */
    public static String getDateTooString(Date date) {

        SimpleDateFormat formatter = new SimpleDateFormat(DateStyle.YYYY_MM_DD.getValue());
        String dateString = formatter.format(date);
        return dateString;
    }

    /**
     * @author zhijun.zhao
     * @date 2018/9/11 17:12
     * @param time
     * @return String
     * @Description:   时间格式转译，由data转为字符串
     */
    public static String getTimeTooString(Date time) {

        SimpleDateFormat formatter = new SimpleDateFormat(DateStyle.HH_MM.getValue());
        String dateString = formatter.format(time);
        return dateString;
    }

     /**
      * @author zhijun.zhao
      * @date 2018/9/12 13:52
      * @param localDate
      * @return Date
      * @Description:  LocalDateTime 转Date
      */
     public static Date getLocalDateTimetoDate(LocalDateTime localDate){
             ZoneId zoneId = ZoneId.systemDefault();
             ZonedDateTime zdt = localDate.atZone(zoneId);

             return  Date.from(zdt.toInstant());
     }


    public static Date getLocalDateToDate(LocalDate localDate) {
        if(null == localDate) {
            return null;
        }
        ZonedDateTime zonedDateTime = localDate.atStartOfDay(ZoneId.systemDefault());
        return Date.from(zonedDateTime.toInstant());
    }

    /**
     * @author zhijun.zhao
     * @date 2018/9/13 19:10
     * @param date
     * @return LocalDateTime
     * @Description:  date与LocalDateTime进行转换
     */
    public static LocalDateTime getDateToLocalDateTime(Date date){
        Instant instant = date.toInstant();
        ZoneId zoneId = ZoneId.systemDefault();

        return instant.atZone(zoneId).toLocalDateTime();
    }

    /**
     * @param date
     * @return LocalDateTime
     * @author zhijun.zhao
     * @date 2018/9/13 19:10
     * @Description: date与LocalDate进行转换
     */
    public static LocalDate getDateToLocalDate(Date date) {
        Instant instant = date.toInstant();
        ZoneId zoneId = ZoneId.systemDefault();

        return instant.atZone(zoneId).toLocalDate();
    }


    /**
     * @author zhijun.zhao
     * @date 2018/10/25 10:06
     * @param
     * @return String
     * @Description:  获取当前年份
     */
    public static String getSysYear() {
        Calendar date = Calendar.getInstance();
        String year = String.valueOf(date.get(Calendar.YEAR));
        return year;
    }

    /**
     * @author zhijun.zhao
     * @date 2018/10/25 10:09
     * @param
     * @return String
     * @Description: 获取当前月份
     */
    public static String getSysMonth() {
        Calendar date = Calendar.getInstance();
        String month = String.valueOf(date.get(Calendar.MONTH) + 1);
        return month;
    }

    /**
     * @author zhijun.zhao
     * @date 2018/10/25 10:10
     * @param
     * @return String
     * @Description: 获取当前日
     */
    public static String getSysDay() {
        Calendar date = Calendar.getInstance();
        String day = String.valueOf(date.get(Calendar.DAY_OF_MONTH));
        return day;
    }

    /**
     * @param birthDay
     * @return int
     * @author liyucheng
     * @date 2018/11/7 17:03
     * @description 由出生日期获得年龄  精确到天
     */
    public static int calcAge(Date birthDay) {
        Calendar cal = Calendar.getInstance();
        if (cal.before(birthDay)) {
            throw new IllegalArgumentException("出生日期不能晚于当前日期");
        }
        int yearNow = cal.get(Calendar.YEAR);
        int monthNow = cal.get(Calendar.MONTH);
        int dayOfMonthNow = cal.get(Calendar.DAY_OF_MONTH);
        cal.setTime(birthDay);

        int yearBirth = cal.get(Calendar.YEAR);
        int monthBirth = cal.get(Calendar.MONTH);
        int dayOfMonthBirth = cal.get(Calendar.DAY_OF_MONTH);

        int age = yearNow - yearBirth;

        if (monthNow <= monthBirth) {
            if (monthNow == monthBirth) {
                if (dayOfMonthNow < dayOfMonthBirth) {
                    age--;
                }
            } else {
                age--;
            }
        }
        return age;
    }

    /**
     * @param date, week
     * @return int
     * @author li.chen
     * @date 2018/12/17 13:37
     * @description 获取当日所在周指定星期的日期
     */
    public static Date getThisWeekSomeday(Date date, Integer week) {
        SimpleDateFormat sdf2 = new SimpleDateFormat("yyyy-MM-dd");
        Calendar cal = Calendar.getInstance();
        cal.setTime(date);

        // 得到今天是周几
        int a = cal.get(Calendar.DAY_OF_WEEK) - 1;
        // 周几,如果是周日 变为7
        if (a == 0) {
            a = 7;
        }
        // 当前时间减去 几天得到周一的时间
        long resDateTime = date.getTime() - (a * 86400000);
        // 再加上1天的时间
        resDateTime += 86400000;
        //得到本周一日期
        Date resDate = new Date(resDateTime);
        cal.setTime(resDate);
        cal.add(Calendar.DATE, week - 1);
        return cal.getTime();
    }

    /**
     * @param date, week
     * @return int
     * @author li.chen
     * @date 2018/12/17 13:37
     * @description 获取指定日期一周后的日期
     */
    public static List<Date> getNextWeekSomeday(Date date, Integer count) {
        Calendar cal = Calendar.getInstance();
        List<Date> dateList = new ArrayList<>();
        for (int i = 0; i < count;i ++){
            cal.setTime(date);
            cal.add(Calendar.DATE, 7);
            Date day = cal.getTime();
            dateList.add(day);
            date = cal.getTime();
        }
        return dateList;
    }

    /**
     * @param date, week
     * @return int
     * @author li.chen
     * @date 2019/01/21 17:11
     * @description 获取指定日期起指定天数的日期集合
     */
    public static List<Date> getDates(Date date, Integer count){
        Calendar cal = Calendar.getInstance();
        List<Date> dateList = new ArrayList<>();
        dateList.add(date);
        for (int i = 0; i < count - 1;i ++){
            cal.setTime(date);
            cal.add(Calendar.DATE, 1);
            Date day = cal.getTime();
            dateList.add(day);
            date = cal.getTime();
        }
        return dateList;
    }

    /**
     * @param timeStart, timeEnd
     * @return int
     * @author li.chen
     * @date 2018/12/18 13:37
     * @description 获取两个时间的时间差（毫秒）
     */
    public static Long getUseTime(Date timeStart, Date timeEnd){

        long start = timeStart.getTime();
        long end = timeEnd.getTime();
        return end - start;
    }

    /**
     * @param date
     * @return int
     * @author li.chen
     * @date 2019/11/29 17:36
     * @description Date 转 LocalTime
     */
    public static LocalTime dateToDateTime(Date date) {
        return date.toInstant().atZone(ZoneOffset.ofHours(8)).toLocalTime();
    }

    /**
     * @param t1
     * @param t2
     * @return com.arrail.common.model.ReturnInfo
     * @author li.chen
     * @date 2019/11/29 17:53
     * @description: 计算localTime 时间差
     */
    public static Integer minuteSubtract(LocalTime t1, LocalTime t2){
        Integer result = 0;
        int i = t1.compareTo(t2);
        switch (i){
            case -1:
                result = (t2.getHour() - t1.getHour()) * 60 + (t2.getMinute() - t1.getMinute());
                break;
            case 1:
                result = (t1.getHour() - t2.getHour()) * 60 + (t1.getMinute() - t2.getMinute());
                break;
            default:
                result = 0;
        }
        return result;
    }

    /**
     * @param timeStart, timeEnd
     * @return int
     * @author li.chen
     * @date 2018/12/18 13:37
     * @description 根据起始时间与时长（分钟）计算结束时间
     */
    public static Date getTimeEnd(Date timeStart, Integer timeLength){

        long start = timeStart.getTime();
        long end = start + (timeLength * 60 * 1000);
        Date date = new Date(end);
        SimpleDateFormat sdf = new SimpleDateFormat("HH:mm:ss");
        String timeEndStr = sdf.format(date);
        Date timeEnd = null;
        try {
            timeEnd = sdf.parse(timeEndStr);
        } catch (ParseException e) {
            e.printStackTrace();
        }
        return timeEnd;
    }

    /**
     * @param timeStart, timeEnd
     * @return int
     * @author li.chen
     * @date 2019/03/04 15:05
     * @description 获取两个时间的段数（例：3:00-5:00 为2, 3:00-5:30 为3, 3:30-5:30 为3）
     */
    public static Integer getParagraphOfTwoTime(Date timeStart, Date timeEnd){

        SimpleDateFormat sdfHour = new SimpleDateFormat("HH");
        SimpleDateFormat sdfMinute = new SimpleDateFormat("mm");

        String startStrHour = sdfHour.format(timeStart);
        String endStrHour = sdfHour.format(timeEnd);
        Integer flag = Integer.valueOf(endStrHour) - Integer.valueOf(startStrHour);

        String endStrMinute = sdfMinute.format(timeEnd);
        if (Integer.valueOf(endStrMinute) != 0){
            //结束时间不为整点，段数+1
            flag += 1;
        }

        return flag;
    }

    /**
     * @param date
     * @return int
     * @author li.chen
     * @date 2018/12/21 11:38
     * @description 获取当日为周几
     */
    public static Integer getweek(Date date){

        Calendar cal = Calendar.getInstance();
        cal.setTime(date);

        // 得到今天是周几
        int a = cal.get(Calendar.DAY_OF_WEEK) - 1;
        // 周几,如果是周日 变为7
        if (a == 0) {
            a = 7;
        }

        return a;
    }

    /**
     * @param date
     * @return int
     * @author li.chen
     * @date 2018/12/22 10:35
     * @description 根据起始时间获取指定天数的日期区间
     */
    public static List<Date> getDateList(Date date, Integer countDay){

        //根据展示天数自增日期，存入集合
        List<Date> dateList = new ArrayList<>();
        for (int i = 0; i < countDay; i++)
        {
            dateList.add(date);
            Calendar c = Calendar.getInstance();
            c.setTime(date);
            c.add(Calendar.DATE, 1);
            date = c.getTime();
        }
        return dateList;
    }

    /**
     * 根据小时判断是否为上午、中午、下午
     *
     * @param startDate
     * @param endDate
     * @return 上午下午，全天不返回东西文字
     * @author shaobin.wang
     */
    public static String getHourDuringDay(Date startDate, Date endDate) {
        try {
            SimpleDateFormat simpleDateFormat = new SimpleDateFormat("HH:mm:ss");
            String format = simpleDateFormat.format(startDate);
            Date parse = simpleDateFormat.parse("18:00:00");
            GregorianCalendar ca = new GregorianCalendar();
            ca.setTime(simpleDateFormat.parse(format));
            int i = ca.get(GregorianCalendar.AM_PM);
            if (i == 0) {
                //如果是上午的话他结束时间大于晚上八点那就是全天
                if (endDate.getTime() >= parse.getTime()) {
                    //全天
                    return "";
                }
                return "上午";
            }
            if (i == 1) {
                return "下午";
            }
        } catch (ParseException e) {
            e.printStackTrace();
        }
        return "失败";
    }

    /**
     * @param year, month
     * @return int
     * @author li.chen
     * @date 2018/12/22 10:35
     * @description 获取指定年月所有日期
     */
    public static List<Date> getDatesFromYearAndMonth(Integer year, Integer month){
        SimpleDateFormat dateFormatYear = new SimpleDateFormat("yyyy-MM-dd");
        List<String> fullDayList = new ArrayList<>(32);
        List<Date> dateList = new ArrayList<>();
        // 获得当前日期对象
        Calendar cal = Calendar.getInstance();
        cal.clear();// 清除信息
        cal.set(Calendar.YEAR, year);
        // 1月从0开始
        cal.set(Calendar.MONTH, month-1 );
        // 当月1号
        cal.set(Calendar.DAY_OF_MONTH,1);
        int count = cal.getActualMaximum(Calendar.DAY_OF_MONTH);
        for (int j = 1; j <= count ; j++) {
            fullDayList.add(dateFormatYear.format(cal.getTime()));
            cal.add(Calendar.DAY_OF_MONTH,1);
        }
        for (String dateStr : fullDayList){
            try {
                Date date = dateFormatYear.parse(dateStr);
                dateList.add(date);
            } catch (ParseException e) {
                e.printStackTrace();
            }
        }
        return dateList;
    }

    public static Date getDate(Date date){
        DateFormat df = new SimpleDateFormat("yyyy-MM-dd");
        String d = df.format(date);
        SimpleDateFormat formatter = new SimpleDateFormat("yyyy-MM-dd");
        ParsePosition pos = new ParsePosition(0);
        Date strtodate = formatter.parse(d, pos);
        return strtodate;
    }

    /**
     * @param time
     * @return int
     * @author li.chen
     * @date 2019/03/01 11:07
     * @description 判断传入时间分钟数对小时占比（例 time = "09:20"，占比2/3）
     */
    public static Long getProportionOfTime(Date time, Integer status){

        SimpleDateFormat sdfHour = new SimpleDateFormat("HH");
        SimpleDateFormat sdfTime = new SimpleDateFormat("HH:mm:ss");
        String startStr = sdfHour.format(time) + ":00:00";
        Date dateStr = null;
        try {
            dateStr = sdfTime.parse(startStr);
        } catch (ParseException e) {
            e.printStackTrace();
        }

        Calendar end = Calendar.getInstance();
        end.setTime(dateStr);
        end.add(Calendar.HOUR,1);
        Date nextTime = end.getTime();
        String nextTimeStr = sdfTime.format(nextTime);
        try {
            nextTime = sdfTime.parse(nextTimeStr);
        } catch (ParseException e) {
            e.printStackTrace();
        }

        long useTime = 0;
        long startTime = time.getTime();
        if (status.equals(1)){
            //起始时间
            long endTime = nextTime.getTime();
            useTime = endTime - startTime;
        } else {
            //结束时间
            long dateStart = dateStr.getTime();
            useTime = startTime - dateStart;
            if (useTime == 0){
                //结束时间为整点，时段占用为1小时整
                useTime = 60 * 60 * 1000;
            }
        }

        return useTime;
    }
    /**
     * @param referenceMonth
     * @return java.util.List<java.util.Date>
     * @author shaobin.wang
     * @date 2019/01/07 10:52
     * @description 根据一个日期获取当前月所有天日期集合
     */
    public static List<Date> getDayListOfMonth(Date referenceMonth) {
        SimpleDateFormat sp = new SimpleDateFormat("yyyy-MM-dd");
        List<Date> list = new ArrayList<>();
        Calendar aCalendar = Calendar.getInstance(Locale.CHINA);
        aCalendar.setTime(referenceMonth);
        //年份
        int year = aCalendar.get(Calendar.YEAR);
        //月份
        int month = aCalendar.get(Calendar.MONTH) + 1;
        int day = aCalendar.getActualMaximum(Calendar.DATE);
        String monthStr = "0";
        if (month < NumEnum.TEN.getCode()) {
            monthStr = "0" + month;
        } else {
            monthStr = String.valueOf(month);
        }
        for (int i = 1; i <= day; i++) {
            String days = "0";
            if (i < NumEnum.TEN.getCode()) {
                days = "0" + i;
            } else {
                days = String.valueOf(i);
            }
            String aDate = year + "-" + monthStr + "-" + days;
            try {
                Date date = sp.parse(aDate);
                list.add(date);
            } catch (ParseException e) {
                e.printStackTrace();
            }

        }
        return list;
    }

    /**
     * @author shaobin.wang
     * @date 2019/07/16 10:54
     * @description 通过开始时间结束时间返回所有的间隔日期
     */
    public static List<Date> findIntervalDates(Date statTime, Date endTime) {
        List<Date> allDate = new ArrayList();

        long s = Long.valueOf(statTime.getTime());

        long e = Long.valueOf(endTime.getTime());

        //只有结束时间大于开始时间时才进行查询
        if (s < e) {
            allDate.add(statTime);
            Calendar calBegin = Calendar.getInstance();
            // 使用给定的 Date 设置此 Calendar 的时间
            calBegin.setTime(statTime);
            Calendar calEnd = Calendar.getInstance();
            // 使用给定的 Date 设置此 Calendar 的时间
            calEnd.setTime(endTime);
            // 测试此日期是否在指定日期之后
            while (endTime.after(calBegin.getTime())) {
                // 根据日历的规则，为给定的日历字段添加或减去指定的时间量
                calBegin.add(Calendar.DAY_OF_MONTH, 1);
                allDate.add(calBegin.getTime());
            }
            return allDate;
        }else if (s == e){
            allDate.add(statTime);
        }
        return allDate;
    }



    /**
     * 时间就近取整:<=30分向前取整,>30分向后取整 ,=00 那就返回 00
     * Author:wsb
     * @param dateTime inTime 07:56
     * @return outTime 08:00
     */
    public static Date getInitialDateTime(Date dateTime) {
        LocalDateTime localDateTime = getDateToLocalDateTime(dateTime);
        LocalTime localTime = localDateTime.toLocalTime();
        int minute = localTime.getMinute();

        if (minute != 0 && minute != 30) {
            if (minute > 30) {
                localTime = localTime.plusHours(1).withMinute(0);
            } else if (minute < 30) {
                localTime = localTime.withMinute(30);
            }
        }
        ZonedDateTime zonedDateTime = LocalDateTime.of(localDateTime.getYear(), localDateTime.getMonth(), localDateTime.getDayOfMonth(),
                localTime.getHour(), localTime.getMinute()).atZone(ZoneId.systemDefault());
        return Date.from(zonedDateTime.toInstant());
    }

    public static void main(String[] args) throws ParseException {
        LocalDate now = LocalDate.now();

        LocalDate with = now.with(DayOfWeek.MONDAY);
        System.out.println("一个周");
        System.out.println(with);
        System.out.println(with.plusDays(6L));

        /*一个月*/
        LocalDate with1 = now.with(TemporalAdjusters.firstDayOfMonth());
        LocalDate with2 = now.with(TemporalAdjusters.lastDayOfMonth());
        System.out.println("一个月");
        System.out.println(with1);
        System.out.println(with2);

        /*最近三个月*/
        LocalDate with3 = now.with(TemporalAdjusters.firstDayOfMonth());
        LocalDate with4 = now.plusMonths(3).with(TemporalAdjusters.firstDayOfMonth()).plusDays(-1);
        System.out.println("最近三个月");
        System.out.println(with3);
        System.out.println(with4);

        /*六个月*/
        LocalDate with5 = now.with(TemporalAdjusters.firstDayOfMonth());
        LocalDate with6 = now.plusMonths(6).with(TemporalAdjusters.firstDayOfMonth()).plusDays(-1);
        System.out.println("六个月");
        System.out.println(with5);
        System.out.println(with6);
    }

    /**
     * 根据资源配置规则得出相应的日期集合
     * 规则区间（无1/ 一天2/ 一周3/ 一个月4/ 三个月5/ 六个月6）
     *
     * @param resourceRuleMenuDto
     * @param appointmentDate
     * @author shaobin.wang
     * @date 2019/12/31 10:18
     */
    public static void resourceRuleDateList(ResourceRuleMenuDto resourceRuleMenuDto, Date appointmentDate) {
        LocalDate now = getDateToLocalDate(appointmentDate);
        Integer ruleInterval = resourceRuleMenuDto.getRuleInterval();
        if (ruleInterval == 2) {
            resourceRuleMenuDto.setEndTime(Date.from(now.atStartOfDay(ZoneId.systemDefault()).toInstant()));
            resourceRuleMenuDto.setStartTime(Date.from(now.atStartOfDay(ZoneId.systemDefault()).toInstant()));
        }
        if (ruleInterval == 3) {
            LocalDate with = now.with(DayOfWeek.MONDAY);
            resourceRuleMenuDto.setStartTime(Date.from(with.atStartOfDay(ZoneId.systemDefault()).toInstant()));
            resourceRuleMenuDto.setEndTime(Date.from(with.plusDays(6L).atStartOfDay(ZoneId.systemDefault()).toInstant()));
        }
        if (ruleInterval == 4) {
            LocalDate first = now.with(TemporalAdjusters.firstDayOfMonth());
            LocalDate last = now.with(TemporalAdjusters.lastDayOfMonth());
            resourceRuleMenuDto.setStartTime(Date.from(first.atStartOfDay(ZoneId.systemDefault()).toInstant()));
            resourceRuleMenuDto.setEndTime(Date.from(last.atStartOfDay(ZoneId.systemDefault()).toInstant()));
        }
        if (ruleInterval == 5) {
            LocalDate first = now.with(TemporalAdjusters.firstDayOfMonth());
            LocalDate last = now.plusMonths(3).with(TemporalAdjusters.firstDayOfMonth()).plusDays(-1);
            resourceRuleMenuDto.setStartTime(Date.from(first.atStartOfDay(ZoneId.systemDefault()).toInstant()));
            resourceRuleMenuDto.setEndTime(Date.from(last.atStartOfDay(ZoneId.systemDefault()).toInstant()));
        }
        if (ruleInterval == 6) {
            LocalDate first = now.with(TemporalAdjusters.firstDayOfMonth());
            LocalDate last = now.plusMonths(6).with(TemporalAdjusters.firstDayOfMonth()).plusDays(-1);
            resourceRuleMenuDto.setStartTime(Date.from(first.atStartOfDay(ZoneId.systemDefault()).toInstant()));
            resourceRuleMenuDto.setEndTime(Date.from(last.atStartOfDay(ZoneId.systemDefault()).toInstant()));
        }
    }

    /**
     * 根据分页条数生成日历集合
     *
     * @author shaobin.wang
     * @date 2020/6/23 16:01
     */
    public static List<Date> getDateListByPageSize(LocalDate queryLocalDate, Integer pageNow, Integer pageSize) {
        List<Date> dateList = Lists.newArrayList();

        queryLocalDate = queryLocalDate.plusDays(pageSize * (pageNow - 1));

        dateList.add(Date.from(queryLocalDate.atStartOfDay(ZoneId.systemDefault()).toInstant()));
        int flag = 1;
        while (true) {
            queryLocalDate = queryLocalDate.plusDays(1);
            dateList.add(Date.from(queryLocalDate.atStartOfDay(ZoneId.systemDefault()).toInstant()));
            flag++;
            if (flag == pageSize) {
                break;
            }
        }
        return dateList;
    }
}
